package com.nuoniu.sibanyun.controller.production;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.production.ErpStation;
import com.nuoniu.sibanyun.service.production.IErpStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 工位 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-03-06
 */
@RestController
@RequestMapping("/erp/station")
@Api(tags = "工位管理")
public class ErpStationController extends BaseController {

    @Autowired
    private IErpStationService stationService;

    @ApiOperation("获取工位列表")
    @GetMapping("pageList")
    public HttpResult pageList(Page page, ErpStation station) {
        return HttpResult.ok(stationService.pageList(page, station));
    }

    @ApiOperation("保存工位")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpStation station) {
        if(StringUtils.isBlank(station.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }
        if(StringUtils.isBlank(station.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        stationService.saveStation(station);
        return HttpResult.ok();
    }

    @ApiOperation("删除工位")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        stationService.deleteById(id);
        return HttpResult.ok();
    }
}
